<?php echo $html->script(array("jquery.form.js", "datepicker.js")); ?>
<?php
$this->Html->addCrumb('My Information');
?>
<script type="text/javascript">
    // <![CDATA[
    function pad(value, length) {
        length = length || 2;
        return "0000".substr(0,length - Math.min(String(value).length, length)) + value;
    };
    // ]]>
</script>
<style type="text/css">
    a.date-picker-control:link, a.date-picker-control:visited {float: left;height: 16px;text-indent: -9999px;}
</style>
<div id="left">
    <div class="search-title"><?php __('My Information'); ?></div>
    <?php
    echo $this->Session->flash();
    if ($this->Session->check('Message.auth'))
        echo $this->Session->flash('auth');
    ?>
    <br />    
    <div class="div_content">
        <form method="post" id="edit_admin" action="<?php echo Configure::read('base_url') . "users/my_information"; ?>">
            <table>
                <tbody>
                    <tr>
                        <td colspan="2">
                            <table width="82%" border="0" cellspacing="5" cellpadding="0">
                                <tr>
                                    <td width="266" align="right">First Name<em>*</em></td>
                                    <td width="247">
                                        <?php
                                        echo $this->Form->hidden('User.id');
                                        echo $this->Form->input('User.first_name', array('label' => false, 'div' => false, 'class' => 'required', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Last Name<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.last_name', array('label' => false, 'div' => false, 'class' => 'required', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right"> Street Address<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.address', array('label' => false, 'div' => false, 'class' => 'required', 'size' => '60'));
                                        echo $this->Form->input('User.address2', array('label' => false, 'div' => false, 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">City<em>*</em></td>
                                    <td>
                                        <div id="userCityIdWrapper">
                                            <?php echo $this->Form->input('User.city_id', array('label' => false, 'div' => false, 'class' => 'required','selected' => $this->data['User']['city_id'])); ?>
                                        </div>
                                    </td>	
                                </tr>

                                <tr>
                                    <td align="right">State<em>*</em></td>
                                    <td>
                                        <div id="userStateIdWrapper">
                                            <?php
                                            echo $this->Form->input('User.state_id', array('label' => false, 'div' => false,'selected' => $this->data['User']['state_id']));
                                            ?>
                                        </div>
                                    </td>
                                </tr>

                                <tr>    
                                    <td align="right">Zip<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.zip', array('label' => false, 'div' => false, 'class' => 'required', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Country<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.country_id', array('label' => false, 'div' => false, 'class' => 'required', 'empty' => 'Select Country','selected' => $this->data['User']['country_id']));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Primary Phone #<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.primary_phone', array('label' => false, 'div' => false, 'maxlength' => "3", 'size' => '4', 'style' => 'float:left;margin-right:10px;'));
                                        echo $this->Form->input('User.phone2', array('label' => false, 'div' => false, 'maxlength' => "3", 'size' => '4', 'style' => 'float:left;margin-right:10px;'));
                                        echo $this->Form->input('User.phone3', array('label' => false, 'div' => false, 'maxlength' => "4", 'size' => '5', 'class' => 'required'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Email<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.email', array('id' => 'email', 'label' => false, 'div' => false, 'class' => 'required email', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Confirm Email<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('cemail', array('label' => false, 'name' => 'cemail', 'div' => false, 'size' => '19', 'value' => $this->data['User']['email'], 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td  align="right">User Id<em>*</em></td>
                                    <td>
                                        <input type="text" disabled="disabled" size="60" name="nothing" value="<?php echo $this->data['User']['username']; ?>"/>        
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Password<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('password', array('label' => false, 'div' => false, 'name' => 'password', 'id' => 'password', 'type' => 'password', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Confirm Password<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('cpassword', array('label' => false, 'div' => false, 'name' => 'cpassword', 'id' => 'cpassword', 'type' => 'password', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Secret Question<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.secretquestion_id', array('empty' => 'Select your Secret question', 'div' => false, 'label' => false, 'class' => 'required', 'style' => "width:375px"));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="right">Your Secret Answer<em>*</em></td>
                                    <td>
                                        <?php
                                        echo $this->Form->input('User.ques_ans', array('label' => false, 'value' => base64_decode($this->data['User']['ques_ans']), 'div' => false, 'class' => 'required', 'size' => '60'));
                                        ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td  style="vertical-align: top; line-height: 20px;" class="tdtext">Date of Birth<em>*</em></td>
                                    <td>
                                        <input type="text" readonly class="w16em required" id="selectDate" name="data[User][dateofbirth]" value="<?php echo $this->data['User']['dateofbirth']; ?>" style="float:left;" />
                                        <script type="text/javascript">
                                            var today     = new Date(),
                                            // low range, 35 days before today's date
                                            //rangeLow  = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 35),
                                            // low range, form today's date
                                            rangeLow  = new Date(today.getFullYear()-150, today.getMonth(), today.getDate()),
                                            // high range, one year after today's date
                                            rangeHigh = new Date(today.getFullYear()-18, today.getMonth(), today.getDate())

                                            var opts = {
                                                formElements:{"selectDate":"Y-ds-m-ds-d"},
                                                showWeeks:true,
                                                statusFormat:"l-cc-sp-d-sp-F-sp-Y",
                                                // Set some dynamically calculated ranges
                                                rangeLow:rangeLow.getFullYear() + "" + pad(rangeLow.getMonth()+1) + pad(rangeLow.getDate()),
                                                rangeHigh:rangeHigh.getFullYear() + "" + pad(rangeHigh.getMonth()+1) + pad(rangeHigh.getDate())

                                            };
                                            if(jQuery("#fd-selectDate").html()!=null){
                                                jQuery('#fd-selectDate').remove();
                                            }
                                            datePickerController.createDatePicker(opts);
                                        </script>
                                    </td>
                                </tr>

                                <tr>
                                    <td width="144">
                                    </td>
                                    <td width="347"><input type="submit" name="button" class="button" id="button" value="Update" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </tbody></table>
        </form>
    </div>
    <div class="div_bottom"></div>
</div>


<script type="text/javascript">
    jQuery(document).ready(function(){
        //Populate City drop down on change State drop down
        jQuery("#UserStateId").live('change',function () {
            var stateId=jQuery(this).val();
            var URL="<?php echo Configure::read('base_url'); ?>users/loadCity/"+stateId;          
            jQuery("#UserCityId").html("<option value='0'>loading...</option>");
            jQuery("#userCityIdWrapper").load(URL);
        
        });
        //Populate State drop down on change Country dropdown
        jQuery("#UserCountryId").live('change',function () {
            var countryId=jQuery(this).val();
            var URL="<?php echo Configure::read('base_url'); ?>users/loadState/"+countryId;          
            jQuery("#UserStateId").html("<option value='0'>loading...</option>");
            jQuery("#userStateIdWrapper").load(URL);
        
        });
        var v = jQuery("#edit_admin").validate({
            rules: {
                email:{
                    'required':true,
                    'email':true
                },
                cemail: {
                    required: true,
                    equalTo: '#email'
                },
                cpassword: {
                    equalTo: '#password'
                }
            }

        });

    });
</script>